import { defineStore } from "pinia"
import request from '@/uitils/request'
// 导入类型注解
import {ApiRes,HomeBanner,GoodItems,HotGoods,BrandItem,ProctuctGoods,SpecialList } from '@/types/data'

const useHomeStore=defineStore('home',{
    state(){
        return{
            // 轮播图数据
            bannerList:[]as HomeBanner[],
            // 新鲜好物数据
            newGoodsList:[] as GoodItems[],
            // 人气推荐
            hotGoodsList:[] as HotGoods[],
            // 热门品牌
            brandList:[] as BrandItem[],
            // 首页主体
            productList:[] as ProctuctGoods[],
            // 专题
            specialList:[] as SpecialList[]
        }
    },
    actions:{
        // 获取轮播图数据
       async getBannerList(){
            const res=await request.get<ApiRes<HomeBanner[]>>('/home/banner')
            this.bannerList=res.data.result
        },
        // 获取新鲜好物
       async getNewGoods(){
            const res=await request.get<ApiRes<GoodItems[]>>('/home/new')
            this.newGoodsList=res.data.result
        },
        // 人气推荐
        async getHotList(){
            const res=await request.get<ApiRes<HotGoods[]>>('/home/hot')
            this.hotGoodsList=res.data.result
        },
        // 热门品牌
        async getBrandList(){
            const res=await request.get<ApiRes<BrandItem[]>>('/home/brand')
            this.brandList=res.data.result
        },
        // 首页主体 商品
        async getProductList(){
            const res= await request.get<ApiRes<ProctuctGoods[]>>('/home/goods')
            this.productList=res.data.result
        },
        // 专题
        async getSpeicalList(){
            const res=await request.get<ApiRes<SpecialList[]>>('/home/special')
            // console.log(res);
            this.specialList=res.data.result
        }
    },
    getters:{}
})
export default useHomeStore